from PyQt4.QtCore import *
from PyQt4.QtGui import *
from zmq import PUSH
import random

from zmqsocket import *

class Ventilator(QWidget):
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)

        self.setWindowTitle("Venitlator")

        QVBoxLayout(self)
        _start=QPushButton("Start")
        _start.clicked.connect(self.start)
        self.layout().addWidget(_start)

        self.sender=ZmqSocket(PUSH, self)
        self.sender.bind("tcp://*:5557")

        self.sink=ZmqSocket(PUSH, self)

    def start(self):
        self.sink.connect("tcp://localhost:5558")

        self.sink.send('0')
 
        random.seed()
        total_msec=0
        for i in range(100):
            workload=random.randint(1,100)
            total_msec+=workload
            self.sender.send(str(workload))

if __name__=="__main__":
    from sys import argv
    a=QApplication(argv)
    v=Ventilator()
    v.show()
    exit(a.exec_())
